﻿using System;
using System.Windows.Forms;
using ArtMath.Resource;
using ArtMath.Flag;
using ArtMath.Core.Helper;

namespace ArtMath.Window
{
    public partial class AddSketchpadWindow : Form
    {
        public string PadName
        {
            get { return tbPadName.Text; }
        }
        public CoordinateSystemType CoordinateType
        {
            get
            {
                if (rbRC.Checked)
                {
                    return CoordinateSystemType.RectangularCoordinate;
                }
                else if (rbSC.Checked)
                {
                    return CoordinateSystemType.PolarCoordinate;
                }
                return CoordinateSystemType.None;
            }
        }
        public AddSketchpadWindow(Predicate<string> checkExist, string docTitle)
        {
            InitializeComponent();
            tbPadName.Text = Resources.Translate("UnnamedSketchpad");
            Flags.Ctrl = false;
            btnOK.Click += (object sender, EventArgs e) =>
            {
                if (string.IsNullOrEmpty(PadName) || PadName == Resources.Translate("HomePage"))
                {
                    MessageBox.Show(Resources.Translate("InvalidSketchpadName"), Resources.Translate("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (checkExist(PadName))
                    {
                        if (MessageBox.Show(string.Format(Resources.Translate("AddExistedSketchpad"), docTitle, PadName), Resources.Translate("Ask"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            tbPadName.Text = Utility.GetNextAvailableName(PadName, checkExist);
                        }
                        else
                        {
                            return;
                        }
                    }
                    DialogResult = DialogResult.OK;
                }
            };
        }
        private void cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
